package com.gzpi.hwgggh.controller;

import com.gzpi.hwgggh.entity.*;
import com.gzpi.hwgggh.service.DWService;
import com.gzpi.hwgggh.service.StatisticsService;
import com.gzpi.hwgggh.sysenum.EnumErrorCode;
import com.gzpi.hwgggh.utils.*;
import com.gzpi.hwgggh.vo.ExportConditionVo;
import com.gzpi.hwgggh.vo.StatisticsGraphVo;
import com.gzpi.hwgggh.vo.StatisticsTableVo;
import com.sun.prism.Graphics;
import org.apache.catalina.User;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.sl.usermodel.*;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Units;
import org.apache.poi.xddf.usermodel.XDDFShapeProperties;
import org.apache.poi.xddf.usermodel.chart.*;
import org.apache.poi.xslf.usermodel.*;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.presentationml.x2006.main.CTSlide;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.*;
import java.util.List;

/**
 * @date : 2020-12-21 17:01
 **/
@RestController
@RequestMapping("/Export")
@CrossOrigin
public class ExportFileController {

    @Autowired
    private DWService dwService;

    @Autowired
    private StatisticsService statisticsService;

//    @Value("${BaseObject.imagePath}")
    public String httpImagePath = "http://120.78.141.5/";

    /**
     * 规划模板二
     * @param request
     * @param response
     * @param
     * @return
     */
    @RequestMapping(value = "/GHTWO")
    public Result GHTWO(HttpServletRequest request, HttpServletResponse response, ExportConditionVo exportConditionVo){
        try {
            List<DWX> dwxes = dwService.ExportFileData(exportConditionVo);//获取数据
            if (!(dwxes.size()>0)){
                return Result.createError(EnumErrorCode.ERROR_OBJECT_SEARCH.toString("无数据"));
            }
            System.out.println("数据总数:"+dwxes.size());
            XMLSlideShow slideShow = new XMLSlideShow();
            int num = 1;
            for (DWX dwx : dwxes) {//遍历数据
                slideShow.setPageSize(new java.awt.Dimension(1176, 831));//幻灯片大小
                DWTP dwtp = dwx.getDwtp();
                DWG dwg = dwx.getDwg();

                if (dwtp==null || dwg==null){
                    continue;
                }
                //现状
                List<GGP> ggps = dwx.getXzggps();
                String xzid = dwx.getXSDWBH()+"-(X:0)";
                String szwz = "";
                String gyxs = "";
                String ggcc = "";
                String zywt = "";
                if (ggps!=null){
                    xzid = dwx.getXSDWBH()+"-(X:"+ggps.size()+")";

                    /*Collections.sort(ggps, new Comparator<GGP>() {
                        @Override
                        public int compare(GGP o1, GGP o2) {
                            //升序排序，降序反写
                            Integer o1id = Integer.valueOf(o1.getGGBH().substring(o1.getGGBH().indexOf("_")+1));
                            Integer o2id = Integer.valueOf(o2.getGGBH().substring(o2.getGGBH().indexOf("_")+1));
                            return o1id-o2id;
                        }
                    });*/
                    //保存相同内容编号合并信息
                    Map<String, Object> mapxzszwz = new HashMap<>();
                    Map<String, Object> mapxzgyxs = new HashMap<>();
                    Map<String, Object> mapxzggcc = new HashMap<>();
                    Map<String, Object> mapxzzywt = new HashMap<>();
                    for (GGP ggp : ggps) { //合并编号操作

                        if (!ggp.getFID().equals(dwx.getID())) continue;

                        String id = ggp.getGGBH().substring(ggp.getGGBH().indexOf("_")+1);
                        if (StringUtils.isNotBlank(ggp.getSZWZ())) {
                            if (ggp.getSZWZ().contains("其他") && StringUtils.isNotBlank(ggp.getQTWZ())){
                                CommonTools.getMapData(mapxzszwz, ggp.getQTWZ(), id);
                            }else {
                                CommonTools.getMapData(mapxzszwz, ggp.getSZWZ(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getGYXS())) {
                            CommonTools.getMapData(mapxzgyxs, ggp.getGYXS(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getGGCC())) {
                            String[] ggcc_str = ggp.getGGCC().split("×");
                            Double temp_1 = Double.valueOf(ggcc_str[0]);
                            if(ggcc_str[0].indexOf(".")>0){
                                temp_1 = Double.valueOf(ggcc_str[0].substring(0,ggcc_str[0].indexOf(".")+2));
                            }
                            Double temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf("=")));
                            if((ggcc_str[1].substring(0,ggcc_str[1].indexOf("="))).indexOf(".")>0){
                                temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf(".")+2));
                            }
                            DecimalFormat    df   = new DecimalFormat("######0.0");
                            String temp_3 = temp_1+"×"+temp_2+"="+ df.format(temp_1*temp_2)+"㎡";
                            CommonTools.getMapData(mapxzggcc, temp_3, id);
                        }
                        if(StringUtils.isNotBlank(ggp.getZYWT())) {
                            if (ggp.getZYWT().contains("其他") && StringUtils.isNotBlank(ggp.getQTWT())){
                                CommonTools.getMapData(mapxzzywt, ggp.getQTWT(), id);
                            }else {
                                CommonTools.getMapData(mapxzzywt, ggp.getZYWT(), id);
                            }

                        }
                    }

                    //拼接成字符串
                    szwz = CommonTools.mapSort(mapxzszwz);
                    gyxs = CommonTools.mapSort(mapxzgyxs);
                    ggcc = CommonTools.mapSort(mapxzggcc);
                    zywt = CommonTools.mapSort(mapxzzywt);
                }

                String jzqs = dwx.getJZQS();
                if (jzqs!=null){
                    jzqs = jzqs.substring(0,jzqs.indexOf("（可编辑"));
                    if (StringUtils.isNotBlank(dwx.getQSMC())){
                        jzqs+="("+dwx.getQSMC()+")";
                    }
                }

                //现状图片
                String[] qwts =null;
                String[] xzts =null;
                String qwt = dwtp.getQWT();
                String xzt = dwtp.getXZT();
                if (StringUtils.isNotBlank(qwt) && qwt.contains(";")){
                    qwts = qwt.split(";");
                }else if(StringUtils.isNotBlank(qwt)){
                    qwts = new String[]{qwt};
                }
                if (StringUtils.isNotBlank(xzt) && xzt.contains(";")){
                    xzts = xzt.split(";");
                }else if(StringUtils.isNotBlank(xzt)){
                    xzts = new String[]{xzt};
                }
                //结束
                //规划
                List<GGP> dwgGgps = dwx.getGhggps();
                String ghid = dwx.getXSDWBH()+"-(G:0)";


                String ghszwz="";
                String ghnrlx="";
                String ghgyxs="";
                String ghggcc="";
                String ghcl="";
                String ghzm="";
                String ghsc="";
                if (dwgGgps!=null){
                    ghid = dwx.getXSDWBH()+"-(G:"+dwgGgps.size()+")";

                    /*Collections.sort(dwgGgps, new Comparator<GGP>() {
                        @Override
                        public int compare(GGP o1, GGP o2) {
                            //升序排序，降序反写
                            Integer o1id = Integer.valueOf(o1.getGGBH().substring(o1.getGGBH().indexOf("_")+1));
                            Integer o2id = Integer.valueOf(o2.getGGBH().substring(o2.getGGBH().indexOf("_")+1));
                            return o1id-o2id;
                        }
                    });*/

                    //保存相同内容编号合并信息
                    Map<String,Object> ghmapszwz = new HashMap<>();
                    Map<String,Object> ghmapnrlx = new HashMap<>();
                    Map<String,Object> ghmapgyxs = new HashMap<>();
                    Map<String,Object> ghmapggcc = new HashMap<>();
                    Map<String,Object> ghmapcl = new HashMap<>();
                    Map<String,Object> ghmapzm = new HashMap<>();
                    Map<String,Object> ghmapsc = new HashMap<>();
                    for (GGP ggp : dwgGgps) { //合并编号操作

                        if (!ggp.getFID().equals(dwg.getID()));

                        String id = ggp.getGGBH().substring(ggp.getGGBH().indexOf("_")+1); //获取广告牌编号
                        if (StringUtils.isNotBlank(ggp.getSZWZ())) {
                            if (ggp.getSZWZ().contains("其他") && StringUtils.isNotBlank(ggp.getQTWZ())) {
                                CommonTools.getMapData(ghmapszwz, ggp.getQTWZ(), id);
                            }else{
                                CommonTools.getMapData(ghmapszwz, ggp.getSZWZ(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getNRLX())) {
                            CommonTools.getMapData(ghmapnrlx, ggp.getNRLX(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getGYXS())) {
                            if (ggp.getGYXS().contains("其他") && StringUtils.isNotBlank(ggp.getQTGY())) {
                                CommonTools.getMapData(ghmapgyxs, ggp.getQTGY(), id);
                            }else{
                                CommonTools.getMapData(ghmapgyxs, ggp.getGYXS(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getGGCC())) {
                            String[] ggcc_str = ggp.getGGCC().split("×");
                            Double temp_1 = Double.valueOf(ggcc_str[0]);
                            if(ggcc_str[0].indexOf(".")>0){
                                temp_1 = Double.valueOf(ggcc_str[0].substring(0,ggcc_str[0].indexOf(".")+2));
                            }
                            Double temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf("=")));
                            if(ggcc_str[1].indexOf(".")>0){
                                temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf(".")+2));
                            }
                            DecimalFormat    df   = new DecimalFormat("######0.0");
                            String temp_3 = temp_1+"×"+temp_2+"="+ df.format(temp_1*temp_2)+"㎡";
                            CommonTools.getMapData(ghmapggcc, temp_3, id);
                        }
                        if (StringUtils.isNotBlank(ggp.getCLYD())) {
                            if (ggp.getCLYD().contains("其他") && StringUtils.isNotBlank(ggp.getQTCL())) {
                                CommonTools.getMapData(ghmapcl, ggp.getQTCL(), id);
                            }else{
                                CommonTools.getMapData(ghmapcl, ggp.getCLYD(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getZM())) {
                            CommonTools.getMapData(ghmapzm, ggp.getZM(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getSC())) {
                            CommonTools.getMapData(ghmapsc, ggp.getSC(), id);
                        }
                    }

                    //拼接成字符串
                    ghszwz = CommonTools.mapSort(ghmapszwz);
                    ghnrlx = CommonTools.mapSort(ghmapnrlx);
                    ghgyxs = CommonTools.mapSort(ghmapgyxs);
                    ghggcc = CommonTools.mapSort(ghmapggcc);
                    ghcl = CommonTools.mapSort(ghmapcl);
                    ghzm = CommonTools.mapSort(ghmapzm);
                    ghsc = CommonTools.mapSort(ghmapsc);

                }
                //图片
                String[] ghts = null;
                String[] ghtrs = null;
                String[] ghtys =null;
                String ght = dwtp.getGHT();
                String ghtr = dwtp.getGHTR();
                String ghty = dwtp.getGHTY();
                if (StringUtils.isNotBlank(ght) && ght.contains(";")){
                    ghts = ght.split(";");
                }else if (StringUtils.isNotBlank(ght)){
                    ghts = new String[]{ght};
                }
                if (StringUtils.isNotBlank(ghtr) && ghtr.contains(";")){
                    ghtrs = ghtr.split(";");
                }else if (StringUtils.isNotBlank(ghtr)){
                    ghtrs = new String[]{ghtr};
                }
                if (StringUtils.isNotBlank(ghty) && ghty.contains(";")){
                    ghtys = ghty.split(";");
                }else if (StringUtils.isNotBlank(ghty)){
                    ghtys = new String[]{ghty};
                }

                List<String> GHRimagePath = new ArrayList<>(); //规划图日
                List<String> GHYimagePath = new ArrayList<>(); //规划图夜
                if (ghtrs!=null && ghtrs.length>0){
                    for (String s : ghts) {
                        if (s!=null) {
                            GHRimagePath.add(httpImagePath + s);
                        }
                    }
                }
                if (ghtys!=null && ghtys.length>0){
                    for (String s : ghtys) {
                        if (s!=null) {
                            GHYimagePath.add(httpImagePath + s);
                        }
                    }
                }

                if (ghts!=null && ghts.length>0){
                    for (String s : ghts) {
                        if (s!=null) {
                            if(!(GHRimagePath.size()>0)) {
                                GHRimagePath.add(httpImagePath + s);
                            }
                            if (!(GHYimagePath.size()>0)) {
                                GHYimagePath.add(httpImagePath + s);
                            }
                        }
                    }
                }

                //结束
                XSLFSlide slide = slideShow.createSlide(); //创建幻灯片

                XSLFTable tableXZ = slide.createTable(); //创建表格对象
                Object[][] XZdatas = { //表格行和列 表格行列下标从0开始
                        {"现状点位编号:"+xzid, "", ""},
                        {"区位图", "现状基本信息", ""},
                        {"", "所在路段", (dwx.getSZLD()!=null?dwx.getSZLD():"——")},
                        {"", "建筑名称", (dwx.getJZMC()!=null?dwx.getJZMC():"——")},
                        {"", "建筑性质", (dwx.getJZXZ()!=null?dwx.getJZXZ():"——")},
                        {"", "建筑商业面积", (dwx.getJZMJ()!=null?dwx.getJZMJ():"——")},
                        {"", "建筑权属",(jzqs!=null?jzqs:"——")},
                        {"", "专项规划分区", (dwx.getZXGH()!=null?dwx.getZXGH():"——")},
                        {"现状图", "广告所在位置", (StringUtils.isNotBlank(szwz)?szwz:"——")},
                        {"", "广告工艺形式", (StringUtils.isNotBlank(gyxs)?gyxs:"——")},
                        {"", "广告规格尺寸", (StringUtils.isNotBlank(ggcc)?ggcc:"——")},
                        {"", "广告主要问题", (StringUtils.isNotBlank(zywt)?zywt:"——")}
                };
                for (int i = 0; i < XZdatas.length; i++) {//新建行
                    XSLFTableRow tableRow = tableXZ.addRow();
                    tableRow.setHeight(18D);
                    for (int j = 0; j < XZdatas[i].length; j++) {//新建列
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(XZdatas[i][j]));
                        if (!(i == 1 && j == 0 || i == 8 && j == 0)) { //设置字体居中
                            tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
                            p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        }

                        tableStyle(tableCell); //表格公共样式
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242)); //背景颜色
                            tr.setFontSize(14D); //字体大小
                        }
                        if (i > 0) {
                            tr.setFontSize(10D);
                        }
                        if (i == 0 || i == 1 || j == 0 || j == 1) {
                            tr.setBold(true); //字体加粗
                        }
                    }
                    if (i == 0) {
                        tableRow.mergeCells(0, 2); //跨列 第一行跨
                    }
                    if (i == 1) {
                        tableRow.mergeCells(1, 2);
                    }
                }
                tableXZ.setColumnWidth(0, 235); //设置列宽度
                tableXZ.setColumnWidth(1, 60);
                tableXZ.setColumnWidth(2, 170);
                tableXZ.setRowHeight(10,80D);
                tableXZ.mergeCells(1, 7, 0, 0);
                tableXZ.mergeCells(8, 11, 0, 0);
                tableXZ.setAnchor(new Rectangle2D.Double(40, 30, 455, 368)); //设置表格的生成的   X轴 Y轴 宽 高    注:宽高可能无效



                //图片路径集合
                String[] imagePath = {
                        httpImagePath+(qwts!=null?qwts[0]:""),//区位图
                        httpImagePath+(xzts!=null?xzts[0]:""),//现状图
                        httpImagePath+"/HWGGGH/hwggp/images/zbz.png"//指北针
                };

                //图片的 X轴 Y轴 宽 高
                Double[][] positionOffset = {
                        {43D, 70D, 229D, 140D},
                        {43D, 230D, 229D, 149D},
                        {50D, 75D, 38.08D, 44.24D},
                };

                for (int i = 0; i < imagePath.length; i++) {
                    if (exist(imagePath[i])) {
                        byte[] bytes = image2byte(imagePath[i]); //图片转为的字节
                        XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG); //创建图片对象
                        XSLFPictureShape picture = slide.createPicture(xslfPictureData); //幻灯片插入图片
                        picture.setAnchor(new Rectangle2D.Double(positionOffset[i][0], positionOffset[i][1], positionOffset[i][2], positionOffset[i][3])); //设置图片生成的 X轴 Y轴 宽 高
                    }
                }


                //多个内容的长度   主要用来内容过多导致变形，使下面表格往下移动
                int length = szwz!=null?szwz.length():0 + gyxs!=null?gyxs.length():0 + ggcc!=null?ggcc.length():0 + zywt!=null?zywt.length():0 + jzqs!=null?jzqs.length():0;
//                int length2 = ghszwz.length() + ghnrlx.length() + ghgyxs.length() + ghggcc.length() + ghcl.length() + ghzm.length();
                double twoTableHeight = 434D; //规划表格原 Y轴
                double colorImageHeight = 508D;//颜色图片原 Y轴  （红，黄，蓝，绿）
                double zpwzImageHeight = 735D;//颜色图片原 Y轴  （橙）
                while (length > 375) {
                    length -= 26D;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
                int zywtLength = zywt!=null?zywt.length():0; //主要问题的内容长度
                while (zywtLength > 108) {
                    zywtLength -= 26D;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
                int ggccLength = ggcc!=null?ggcc.length():0; //规格尺寸的内容长度
                while (ggccLength > 108) {
                    ggccLength -= 26D;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
//                while (length2 > 340){
//                    length2 = length2 - 65;
//                    zpwzImageHeight += 10D;
//                }

                XSLFTable tableGH = slide.createTable();

                Object[][] GHdatas = { //规划表格   行列下标从0开始
                        {"规划点位编号:"+ghid, ""},
                        {"规划控制要求", ""},
                        {"政策分区", (dwg.getZCFQ()!=null?dwg.getZCFQ():"——")},
                        {"规划措施", "拆除          提档         保留          新增"},
                        {"所在建筑位置", (StringUtils.isNotBlank(ghszwz)?ghszwz:"——")},
                        {"广告内容类型", (StringUtils.isNotBlank(ghnrlx)?ghnrlx:"——")},
                        {"广告工艺形式", (StringUtils.isNotBlank(ghgyxs)?ghgyxs:"——")},
                        {"广告材料指引", (StringUtils.isNotBlank(ghcl)?ghcl:"——")},
                        {"广告规格尺寸", (StringUtils.isNotBlank(ghggcc)?ghggcc:"——")+"\n（以上为估算尺寸，参考规划图纸位置，以实际尺寸为准）"},
                        {"广告照明方式", (StringUtils.isNotBlank(ghzm)?ghzm:"——")},
                        {"广告色彩指引", (StringUtils.isNotBlank(ghsc)?ghsc:"——")},
                        {"招牌位置及形式引导", "        "+(dwg.getZPWZ()!=null?dwg.getZPWZ():"——")},
                        {"备注", "        "+(dwg.getBZ()!=null?dwg.getBZ():"——")}
                };
                for (int i = 0; i < GHdatas.length; i++) {
                    XSLFTableRow tableRow = tableGH.addRow();//创建行
                    tableRow.setHeight(24D);//设置行高
                    for (int j = 0; j < GHdatas[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(GHdatas[i][j])); //设置表格内容
                        if (!(i == 12 && j == 1 )) { //设置字体居中
                            tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
                            p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        }
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242)); //背景颜色
                            tr.setFontSize(14D);//字体大小
                        }
                        if (i > 0) {
                            tr.setFontSize(10D);
                        }
                        if (j == 0) {
                            tr.setBold(true);//字体是否加粗
                        }
                    }
                    if (i == 0 || i == 1) {
                        tableRow.mergeCells(0, 1);//跨列
                    }
                }
                tableGH.setColumnWidth(0, 110);//设置列宽
                tableGH.setColumnWidth(1, 355);

                //行高
                double ghggccheight = 50D;
                double ghbzHeight = 50D;
                tableGH.setRowHeight(8,ghggccheight);
                tableGH.setRowHeight(12,ghbzHeight);

                tableGH.setAnchor(new Rectangle2D.Double(40D, twoTableHeight, 455D, 376D)); //规划表 X轴 Y轴 宽 高

                //颜色图片
                String[] colorimagePath = {
                        httpImagePath+"HWGGP/static/cc.png",
                        httpImagePath+"HWGGP/static/td.png",
                        httpImagePath+"HWGGP/static/bl.png",
                        httpImagePath+"HWGGP/static/xz.png",
                        httpImagePath+"HWGGP/static/zpwz.png"
                };
                //X轴 Y轴 宽 高
                Double[][] colorpositionOffset = {
                        {220D, colorImageHeight, 14D, 14D},
                        {270D, colorImageHeight, 14D, 14D},
                        {320D, colorImageHeight, 14D, 14D},
                        {365D, colorImageHeight, 14D, 14D},
                        {170D, zpwzImageHeight, 14D, 14D}
                };
                for (int i = 0; i < colorimagePath.length; i++) {
                    byte[] bytes = image2byte(colorimagePath[i]); //图片字节
                    XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);//创建图片对象
                    XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                    picture.setAnchor(new Rectangle2D.Double(colorpositionOffset[i][0], colorpositionOffset[i][1], colorpositionOffset[i][2], colorpositionOffset[i][3]));
                }


                XSLFTable tableGHR = slide.createTable();
                Object[][] GHR = { //规划日表格
                        {"规划日景图"},
                        {""},
                };
                tableGHR.setAnchor(new Rectangle2D.Double(530, 30, 623, 384));
                for (int i = 0; i < GHR.length; i++) {
                    XSLFTableRow tableRow = tableGHR.addRow();
                    for (int j = 0; j < GHR[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setText(String.valueOf(GHR[i][j]));
                        p.setTextAlign(TextParagraph.TextAlign.CENTER); //字体居中
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242)); //背景颜色
                            tr.setFontSize(14D);//字体大小
                            tr.setBold(true);//是否加粗
                        }
                    }
                }
                //设置行高
                tableGHR.setRowHeight(0, 35);   //540
                tableGHR.setRowHeight(1, 354);   //540
                tableGHR.setColumnWidth(0, 623); //370 列宽

//                Double[][] GHRpositionOffset = {
//                        {390D, 40D, 300D, 200D},
//                };
                if (GHRimagePath.size()>0){
                    for (int i = 0; i < GHRimagePath.size(); i++) {
                        if (exist(GHRimagePath.get(i))) {
                            byte[] bytes = image2byte(GHRimagePath.get(i)); //图片字节
                            XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                            XSLFPictureShape picture = slide.createPicture(xslfPictureData);
//                    picture.setAnchor(new Rectangle2D.Double(GHRpositionOffset[i][0], GHRpositionOffset[i][1], GHRpositionOffset[i][2], GHRpositionOffset[i][3]));
                            picture.setAnchor(new Rectangle2D.Double(535D, 80D, 610D, 330D));
                        }
                    }
                }

                XSLFTable tableGHY = slide.createTable();
                Object[][] GHY = {
                        {"规划夜景图"},
                        {""},
                };
                tableGHY.setAnchor(new Rectangle2D.Double(530, 434, 623, 384));
                for (int i = 0; i < GHY.length; i++) {
                    XSLFTableRow tableRow = tableGHY.addRow();
                    for (int j = 0; j < GHY[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setText(String.valueOf(GHY[i][j]));
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                            tr.setBold(true);
                        }
                    }
                }
                tableGHY.setRowHeight(0, 35);   //540
                tableGHY.setRowHeight(1, 354);   //540
                tableGHY.setColumnWidth(0, 623); //370

//                String[] GHYimagePath = {
//                        httpImagePath+"HWGGP/static/GHT_02.png",
//                };


//                Double[][] GHYpositionOffset = {
//                        {390D, 310D, 300D, 200D},
//                };
                if (GHYimagePath.size()>0){
                    for (int i = 0; i < GHYimagePath.size(); i++) {
                        if (exist(GHYimagePath.get(i))) {
                            byte[] bytes = image2byte(GHYimagePath.get(i));
                            XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                            XSLFPictureShape picture = slide.createPicture(xslfPictureData);
//                    picture.setAnchor(new Rectangle2D.Double(GHYpositionOffset[i][0], GHYpositionOffset[i][1], GHYpositionOffset[i][2], GHYpositionOffset[i][3]));
                            picture.setAnchor(new Rectangle2D.Double(535D, 484D, 610D, 330D));
                        }
                    }
                }
                System.out.println("执行第"+num+"遍。");
                num++;
            }
            System.out.println("执行完毕。");
            String fileName = exportConditionVo.getXzq();
            String ssjd = exportConditionVo.getSsjd();
            if (StringUtils.isNotBlank(ssjd) && StringUtils.isNotEmpty(ssjd)){
                fileName += "_"+ssjd;
            }
            if (StringUtils.isBlank(fileName)) fileName = "";
            fileName += "(规划二).pptx";
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            slideShow.write(byteArrayOutputStream);
            byte[] b = byteArrayOutputStream.toByteArray();
            MultipartFile file = new MockMultipartFile(fileName, fileName, MediaType.APPLICATION_OCTET_STREAM.toString(), b);
            FileResult fileResult = FileUtil.saveFileToPath(request, file, HwggConstants.SAVE_PATH + "ExportFile", HwggConstants.MAPPING_PATH + "ExportFile", file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")));
            if (fileResult.isFlag()){
                return Result.createSuccess(EnumErrorCode.SUCCESS_MESSAGE.toString("成功"),fileResult.getHttpUrl());
            }
        }catch (Exception e){
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
        return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString("失败"));
    }

    /**
     * 规划模板一
     * @param request
     * @param response
     * @param
     * @return
     */
    @RequestMapping(value = "/GHONE")
    public Result GHONE(HttpServletRequest request, HttpServletResponse response, ExportConditionVo exportConditionVo){
        try {
            List<DWX> dwxes = dwService.ExportFileData(exportConditionVo);
            if (!(dwxes.size()>0)){
                return Result.createError(EnumErrorCode.ERROR_OBJECT_SEARCH.toString("无数据"));
            }
            System.out.println("数据总数:"+dwxes.size());
            int num = 1;
            XMLSlideShow slideShow = new XMLSlideShow();
            slideShow.setPageSize(new java.awt.Dimension(1176, 831));
            for (DWX dwx : dwxes) {

                DWTP dwtp = dwx.getDwtp();
                DWG dwg = dwx.getDwg();

                if (dwtp == null || dwg == null) {
                    continue;
                }
                //现状
                List<GGP> ggps = dwx.getXzggps();
                String xzid = dwx.getXSDWBH() + "-(X:0)";
                String szwz = "";
                String gyxs = "";
                String ggcc = "";
                String zywt = "";
                if (ggps != null) {
                    xzid = dwx.getXSDWBH() + "-(X:" + ggps.size() + ")";

                    /*Collections.sort(ggps, new Comparator<GGP>() {
                        @Override
                        public int compare(GGP o1, GGP o2) {
                            //升序排序，降序反写
                            Integer o1id = Integer.valueOf(o1.getGGBH().substring(o1.getGGBH().indexOf("_")+1));
                            Integer o2id = Integer.valueOf(o2.getGGBH().substring(o2.getGGBH().indexOf("_")+1));
                            return o1id-o2id;
                        }
                    });*/
                    Map<String, Object> mapxzszwz = new HashMap<>();
                    Map<String, Object> mapxzgyxs = new HashMap<>();
                    Map<String, Object> mapxzggcc = new HashMap<>();
                    Map<String, Object> mapxzzywt = new HashMap<>();
                    for (GGP ggp : ggps) {

                        if (!ggp.getFID().equals(dwx.getID())) continue;

                        String id = ggp.getGGBH().substring(ggp.getGGBH().indexOf("_")+1);
                        if (StringUtils.isNotBlank(ggp.getSZWZ())) {
                            if (ggp.getSZWZ().contains("其他") && StringUtils.isNotBlank(ggp.getQTWZ())){
                                CommonTools.getMapData(mapxzszwz, ggp.getQTWZ(), id);
                            }else {
                                CommonTools.getMapData(mapxzszwz, ggp.getSZWZ(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getGYXS())) {
                            CommonTools.getMapData(mapxzgyxs, ggp.getGYXS(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getGGCC())) {
                            String[] ggcc_str = ggp.getGGCC().split("×");
                            Double temp_1 = Double.valueOf(ggcc_str[0]);
                            if(ggcc_str[0].indexOf(".")>0){
                                temp_1 = Double.valueOf(ggcc_str[0].substring(0,ggcc_str[0].indexOf(".")+2));
                            }
                            Double temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf("=")));
                            if((ggcc_str[1].substring(0,ggcc_str[1].indexOf("="))).indexOf(".")>0){
                                temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf(".")+2));
                            }
                            DecimalFormat    df   = new DecimalFormat("######0.0");
                            String temp_3 = temp_1+"×"+temp_2+"="+ df.format(temp_1*temp_2)+"㎡";
                            CommonTools.getMapData(mapxzggcc, temp_3, id);
                        }
                        if(StringUtils.isNotBlank(ggp.getZYWT())) {
                            if (ggp.getZYWT().contains("其他") && StringUtils.isNotBlank(ggp.getQTWT())){
                                CommonTools.getMapData(mapxzzywt, ggp.getQTWT(), id);
                            }else {
                                CommonTools.getMapData(mapxzzywt, ggp.getZYWT(), id);
                            }

                        }
                    }
                    szwz = CommonTools.mapSort(mapxzszwz);
                    gyxs = CommonTools.mapSort(mapxzgyxs);
                    ggcc = CommonTools.mapSort(mapxzggcc);
                    zywt = CommonTools.mapSort(mapxzzywt);
                }

                String jzqs = dwx.getJZQS();
                if (jzqs != null) {
                    jzqs = jzqs.substring(0, jzqs.indexOf("（可编辑"));
                    if (StringUtils.isNotBlank(dwx.getQSMC())){
                        jzqs+="("+dwx.getQSMC()+")";
                    }
                }

                //现状图片
                String[] qwts = null;
                String[] xzts = null;
                String qwt = dwtp.getQWT();
                String xzt = dwtp.getXZT();
                if (StringUtils.isNotBlank(qwt) && qwt.contains(";")) {
                    qwts = qwt.split(";");
                } else if(StringUtils.isNotBlank(qwt)){
                    qwts = new String[]{qwt};
                }
                if (StringUtils.isNotBlank(xzt) && xzt.contains(";")) {
                    xzts = xzt.split(";");
                } else if (StringUtils.isNotBlank(xzt)){
                    xzts = new String[]{xzt};
                }
                //结束
                //规划
                List<GGP> dwgGgps = dwx.getGhggps();
                String ghid = dwx.getXSDWBH() + "-(G:0)";
                String ghszwz="";
                String ghnrlx="";
                String ghgyxs="";
                String ghggcc="";
                String ghcl="";
                String ghzm="";
                String ghsc="";
                if (dwgGgps != null) {
                    ghid = dwx.getXSDWBH() + "-(G:" + dwgGgps.size() + ")";

                   /* Collections.sort(dwgGgps, new Comparator<GGP>() {
                        @Override
                        public int compare(GGP o1, GGP o2) {
                            //升序排序，降序反写
                            Integer o1id = Integer.valueOf(o1.getGGBH().substring(o1.getGGBH().indexOf("_")+1));
                            Integer o2id = Integer.valueOf(o2.getGGBH().substring(o2.getGGBH().indexOf("_")+1));
                            return o1id-o2id;
                        }
                    });*/

                    Map<String,Object> ghmapszwz = new HashMap<>();
                    Map<String,Object> ghmapnrlx = new HashMap<>();
                    Map<String,Object> ghmapgyxs = new HashMap<>();
                    Map<String,Object> ghmapggcc = new HashMap<>();
                    Map<String,Object> ghmapcl = new HashMap<>();
                    Map<String,Object> ghmapzm = new HashMap<>();
                    Map<String,Object> ghmapsc = new HashMap<>();
                    for (GGP ggp : dwgGgps) {

                        if (!ggp.getFID().equals(dwg.getID())) continue;

                        String id = ggp.getGGBH().substring(ggp.getGGBH().indexOf("_")+1);
                        if (StringUtils.isNotBlank(ggp.getSZWZ())) {
                            if (ggp.getSZWZ().contains("其他") && StringUtils.isNotBlank(ggp.getQTWZ())) {
                                CommonTools.getMapData(ghmapszwz, ggp.getQTWZ(), id);
                            }else{
                                CommonTools.getMapData(ghmapszwz, ggp.getSZWZ(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getNRLX())) {
                            CommonTools.getMapData(ghmapnrlx, ggp.getNRLX(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getGYXS())) {
                            if (ggp.getGYXS().contains("其他") && StringUtils.isNotBlank(ggp.getQTGY())) {
                                CommonTools.getMapData(ghmapgyxs, ggp.getQTGY(), id);
                            }else{
                                CommonTools.getMapData(ghmapgyxs, ggp.getGYXS(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getGGCC())) {
                            String[] ggcc_str = ggp.getGGCC().split("×");
                            Double temp_1 = Double.valueOf(ggcc_str[0]);
                            if(ggcc_str[0].indexOf(".")>0){
                                temp_1 = Double.valueOf(ggcc_str[0].substring(0,ggcc_str[0].indexOf(".")+2));
                            }
                            Double temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf("=")));
                            if((ggcc_str[1].substring(0,ggcc_str[1].indexOf("="))).indexOf(".")>0){
                                temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf(".")+2));
                            }
                            DecimalFormat    df   = new DecimalFormat("######0.0");
                            String temp_3 = temp_1+"×"+temp_2+"="+ df.format(temp_1*temp_2)+"㎡";
                            CommonTools.getMapData(ghmapggcc, temp_3, id);
                        }
                        if (StringUtils.isNotBlank(ggp.getCLYD())) {
                            if (ggp.getCLYD().contains("其他") && StringUtils.isNotBlank(ggp.getQTCL())) {
                                CommonTools.getMapData(ghmapcl, ggp.getQTCL(), id);
                            }else{
                                CommonTools.getMapData(ghmapcl, ggp.getCLYD(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getZM())) {
                            CommonTools.getMapData(ghmapzm, ggp.getZM(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getSC())) {
                            CommonTools.getMapData(ghmapsc, ggp.getSC(), id);
                        }
                    }

                    ghszwz = CommonTools.mapSort(ghmapszwz);
                    ghnrlx = CommonTools.mapSort(ghmapnrlx);
                    ghgyxs = CommonTools.mapSort(ghmapgyxs);
                    ghggcc = CommonTools.mapSort(ghmapggcc);
                    ghcl = CommonTools.mapSort(ghmapcl);
                    ghzm = CommonTools.mapSort(ghmapzm);
                    ghsc = CommonTools.mapSort(ghmapsc);
                }


                //图片
                String[] ghts = null;
                String[] ghtrs = null;
                String[] ghtys = null;
                String ght = dwtp.getGHT();
                String ghtr = dwtp.getGHTR();
                String ghty = dwtp.getGHTY();
                if (StringUtils.isNotBlank(ght) && ght.contains(";")) {
                    ghts = ght.split(";");
                } else if (StringUtils.isNotBlank(ght)){
                    ghts = new String[]{ght};
                }
                if (StringUtils.isNotBlank(ghtr) && ghtr.contains(";")) {
                    ghtrs = ghtr.split(";");
                } else if (StringUtils.isNotBlank(ghtr)){
                    ghtrs = new String[]{ghtr};
                }
                if (StringUtils.isNotBlank(ghty) && ghty.contains(";")) {
                    ghtys = ghty.split(";");
                } else if (StringUtils.isNotBlank(ghty)){
                    ghtys = new String[]{ghty};
                }

                List<String> GHYimagePath = new ArrayList<>();
                if (ghts!=null && ghts.length > 0) {
                    for (String s : ghts) {
                        if (s != null) {
                            GHYimagePath.add(httpImagePath + s);
                        }
                    }
                }
                if (ghtys!=null && ghtys.length > 0) {
                    for (String s : ghtys) {
                        if (s != null) {
                            GHYimagePath.add(httpImagePath + s);
                        }
                    }
                }

                //结束
                XSLFSlide slide = slideShow.createSlide();
                XSLFTable tableXZ = slide.createTable();
                Object[][] XZdatas = {
                        {"现状点位编号："+xzid, ""},
                        {"现状基本信息", ""},
                        {"所在路段", (dwx.getSZLD()!=null?dwx.getSZLD():"——")},
                        {"建筑名称", (dwx.getJZMC()!=null?dwx.getJZMC():"——")},
                        {"建筑性质", (dwx.getJZXZ()!=null?dwx.getJZXZ():"——")},
                        {"建筑商业面积", (dwx.getJZMJ()!=null?dwx.getJZMJ():"——")},
                        {"建筑权属", (jzqs!=null?jzqs:"——")},
                        {"专项规划分区", (dwx.getZXGH()!=null?dwx.getZXGH():"——")},
                        {"广告所在位置", (StringUtils.isNotBlank(szwz)?szwz:"——")},
                        {"广告工艺形式", (StringUtils.isNotBlank(gyxs)?gyxs:"——")},
                        {"广告规格尺寸", (StringUtils.isNotBlank(ggcc)?ggcc:"——")},
                        {"广告主要问题", (StringUtils.isNotBlank(zywt)?zywt:"——")}
                };
                for (int i = 0; i < XZdatas.length; i++) {
                    XSLFTableRow tableRow = tableXZ.addRow();
                    tableRow.setHeight(14D);
                    for (int j = 0; j < XZdatas[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(XZdatas[i][j]));
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                        }
                        if (i > 0) {
                            tr.setFontSize(10D);
                        }
                        if (i == 0 || i == 1 || j == 0) {
                            tr.setBold(true);
                        }
                    }
                    if (i == 0) {
                        tableRow.mergeCells(0, 1);
                    }
                    if (i == 1) {
                        tableRow.mergeCells(0, 1);
                    }
                }
                tableXZ.setColumnWidth(0, 80);
                tableXZ.setColumnWidth(1, 275);
                tableXZ.setRowHeight(10, 60D);
                tableXZ.setAnchor(new Rectangle2D.Double(40, 40, 355, 283));


//                int length = szwz.length() + gyxs.length() + ggcc.length() + zywt.length() + jzqs.length();
                int jzqsLength = jzqs!=null?jzqs.length():0;
                int szwzLength = szwz!=null?szwz.length():0;
                int gyxsLength = gyxs!=null?gyxs.length():0;
                int ggccLength = ggcc!=null?ggcc.length():0;
                int zywtLength = zywt!=null?zywt.length():0;
                double twoTableHeight = 333D;
                double colorImageHeight = 398D;
                double zpwzImageHeight = 680D;
                while (jzqsLength > 44){
                    jzqsLength -= 44;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
                while (szwzLength > 44){
                    szwzLength -= 44;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
                while (gyxsLength > 44){
                    gyxsLength -= 44;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
                while (ggccLength > 138){
                    ggccLength -= 44;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }
                while (zywtLength > 44){
                    zywtLength -= 44;
                    twoTableHeight += 20D;
                    colorImageHeight += 20D;
                    zpwzImageHeight += 20D;
                }

                XSLFTable tableGH = slide.createTable();
                Object[][] GHdatas = {
                        {"规划点位编号："+ghid, ""},
                        {"规划控制要求", ""},
                        {"政策分区", (dwg.getZCFQ()!=null?dwg.getZCFQ():"——")},
                        {"规划措施", "拆除          提档         保留          新增"},
                        {"所在建筑位置", (StringUtils.isNotBlank(ghszwz)?ghszwz:"——")},
                        {"广告内容类型", (StringUtils.isNotBlank(ghnrlx)?ghnrlx:"——")},
                        {"广告工艺形式",(StringUtils.isNotBlank(ghgyxs)?ghgyxs:"——")},
                        {"广告材料指引", (StringUtils.isNotBlank(ghcl)?ghcl:"——")},
                        {"广告规格尺寸", (StringUtils.isNotBlank(ghggcc)?ghggcc:"——")+"\n（以上为估算尺寸，参考规划图纸位置，以实际尺寸为准）"},
                        {"广告照明方式", (StringUtils.isNotBlank(ghzm)?ghzm:"——")},
                        {"广告色彩指引", (StringUtils.isNotBlank(ghsc)?ghsc:"——")},
                        {"招牌位置及形式引导", "        "+(dwg.getZPWZ()!=null?dwg.getZPWZ():"——")},
                        {"备注", "        "+(dwg.getBZ()!=null?dwg.getBZ():"——")}
                };
                for (int i = 0; i < GHdatas.length; i++) {
                    XSLFTableRow tableRow = tableGH.addRow();
                    tableRow.setHeight(14D);
                    for (int j = 0; j < GHdatas[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(GHdatas[i][j]));
                        if (!(i == 12 && j == 1)) {
                            tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
                            p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        }
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                        }
                        if (i > 0) {
                            tr.setFontSize(10D);
                        }
                        if (j == 0) {
                            tr.setBold(true);
                        }
                    }
                    if (i == 0 || i == 1) {
                        tableRow.mergeCells(0, 1);
                    }
                }
                tableGH.setColumnWidth(0, 80);
                tableGH.setColumnWidth(1, 275);

                tableGH.setRowHeight(4,35D);
                tableGH.setRowHeight(5,35D);
                tableGH.setRowHeight(6,35D);
                tableGH.setRowHeight(7,35D);
                tableGH.setRowHeight(8,50D);
                tableGH.setRowHeight(9,35D);
                tableGH.setRowHeight(10,35D);
                tableGH.setRowHeight(11,35D);
                tableGH.setRowHeight(12,50D);

                tableGH.setAnchor(new Rectangle2D.Double(40, twoTableHeight, 355, 450));

                String[] colorimagePath = {
                        httpImagePath+"HWGGP/static/cc.png",
                        httpImagePath+"HWGGP/static/td.png",
                        httpImagePath+"HWGGP/static/bl.png",
                        httpImagePath+"HWGGP/static/xz.png",
                        httpImagePath+"HWGGP/static/zpwz.png"
                };
                Double[][] colorpositionOffset = {
                        {155D, colorImageHeight, 14D, 14D},
                        {205D, colorImageHeight, 14D, 14D},
                        {250D, colorImageHeight, 14D, 14D},
                        {300D, colorImageHeight, 14D, 14D},
                        {135D, zpwzImageHeight, 14D, 14D}
                };
                for (int i = 0; i < colorimagePath.length; i++) {
                    if (exist(colorimagePath[i])) {
                        byte[] bytes = image2byte(colorimagePath[i]);
                        XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                        XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                        picture.setAnchor(new Rectangle2D.Double(colorpositionOffset[i][0], colorpositionOffset[i][1], colorpositionOffset[i][2], colorpositionOffset[i][3]));
                    }
                }


                XSLFTable tableGHR = slide.createTable();
                Object[][] GHR = {
                        {"区位图", "现状图"},
                        {"", ""},
                };
                for (int i = 0; i < GHR.length; i++) {
                    XSLFTableRow tableRow = tableGHR.addRow();
                    for (int j = 0; j < GHR[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setText(String.valueOf(GHR[i][j]));
                        tr.setFontFamily("微软雅黑");
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                            tr.setBold(true);
                        }
                    }
                }
                tableGHR.setRowHeight(0, 20);   //540
                tableGHR.setRowHeight(1, 244);   //540
                tableGHR.setColumnWidth(0, 297); //370
                tableGHR.setColumnWidth(1, 408); //370
                tableGHR.setAnchor(new Rectangle2D.Double(415, 40, 720, 282));

                String[] xztimagePath = {
                        httpImagePath+(qwts!=null?qwts[0]:""),
                        httpImagePath+(xzts!=null?xzts[0]:""),
                        httpImagePath+"/HWGGGH/hwggp/images/zbz.png"
                };
                Double[][] xztpositionOffset = {
                        {416D, 65D, 290D, 240D},
                        {716D, 65D, 402D, 240D},
                        {424D, 70D, 38.08D, 44.24D},
                };
                for (int i = 0; i < xztimagePath.length; i++) {
                    if (exist(xztimagePath[i])) {
                        byte[] bytes = image2byte(xztimagePath[i]);
                        XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                        XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                        picture.setAnchor(new Rectangle2D.Double(xztpositionOffset[i][0], xztpositionOffset[i][1], xztpositionOffset[i][2], xztpositionOffset[i][3]));
                    }
                }

                XSLFTable tableGHY = slide.createTable();
                Object[][] GHY = {
                        {"规划图"},
                        {""},
                };
                for (int i = 0; i < GHY.length; i++) {
                    XSLFTableRow tableRow = tableGHY.addRow();
                    for (int j = 0; j < GHY[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(GHY[i][j]));
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                            tr.setBold(true);
                        }
                    }
                }
                tableGHY.setAnchor(new Rectangle2D.Double(415, 332, 720, 447));
                tableGHY.setRowHeight(0, 20);   //540
                tableGHY.setRowHeight(1, 402);   //540
                tableGHY.setColumnWidth(0, 705); //370

//                String[] GHYimagePath = {
//                        httpImagePath+"HWGGP/static/GHT_02.png",
//                };
//                Double[][] GHYpositionOffset = {
//                        {310D, 250D, 390D, 260D},
//                };
                if (GHYimagePath.size()>0) {
                    for (int i = 0; i < GHYimagePath.size(); i++) {
                        if (exist(GHYimagePath.get(i))) {
                            byte[] bytes = image2byte(GHYimagePath.get(i));
                            XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                            XSLFPictureShape picture = slide.createPicture(xslfPictureData);
//                    picture.setAnchor(new Rectangle2D.Double(GHYpositionOffset[i][0], GHYpositionOffset[i][1], GHYpositionOffset[i][2], GHYpositionOffset[i][3]));
                            picture.setAnchor(new Rectangle2D.Double(418D, 358D, 700D, 398D));
                        }
                    }
                }
                System.out.println("执行第"+num+"遍。");
                num++;
            }
            System.out.println("执行完毕。");
            String fileName = exportConditionVo.getXzq();
            String ssjd = exportConditionVo.getSsjd();
            if (StringUtils.isNotBlank(ssjd) && StringUtils.isNotEmpty(ssjd)){
                fileName += "_"+ssjd;
            }
            if (StringUtils.isBlank(fileName)) fileName = "";
            fileName += "(规划一).pptx";
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            slideShow.write(byteArrayOutputStream);
            byte[] b = byteArrayOutputStream.toByteArray();
            MultipartFile file = new MockMultipartFile(fileName, fileName, MediaType.APPLICATION_OCTET_STREAM.toString(), b);
            FileResult fileResult = FileUtil.saveFileToPath(request, file, HwggConstants.SAVE_PATH + "ExportFile", HwggConstants.MAPPING_PATH + "ExportFile", file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")));
           // FileResult fileResult = FileUtil.saveFileToPath(request, file,  "", "", file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")));
            if (fileResult.isFlag()){
                return Result.createSuccess(EnumErrorCode.SUCCESS_MESSAGE.toString("成功"),fileResult.getHttpUrl());
            }
        }catch (Exception e){
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
        return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString("失败"));
    }

    /**
     * 拆除模板一
     * @param request
     * @param response
     * @param
     * @return
     */
    @RequestMapping(value = "/CCONE")
    public Result CCONE(HttpServletRequest request, HttpServletResponse response, ExportConditionVo exportConditionVo){
        try {
            List<DWC> dwcs = dwService.ExportDWCFileData(exportConditionVo);
            if (!(dwcs.size()>0)){
                return Result.createError(EnumErrorCode.ERROR_OBJECT_SEARCH.toString("无数据"));
            }
            XMLSlideShow slideShow = new XMLSlideShow();
            slideShow.setPageSize(new java.awt.Dimension(1176, 831));
            int q = 0;
            int l = 0;
            System.out.println("数据总数:"+dwcs.size());
            do{
                boolean isBreak = false;
                boolean isTwo = false;
                DWC dwcone = null;
                DWC dwctwo = null;
                if (q==0){
                    l = dwcs.size();
                }
                if (l==2){
                    isBreak = true;
                }
                if (l<2){
                    dwcone = dwcs.get(q);
                    isBreak = true;
                }else{
                    dwcone = dwcs.get(q);
                    dwctwo = dwcs.get((q+1));
                    isTwo = true;
                    l=l-2;
                }
                //拆除one
                if(dwcone==null) {
                    continue;
                }
                DWTP ccdwtpone = dwcone.getDwtp();
                if (ccdwtpone == null) {
                    continue;
                }

                List<GGP> ggpones = dwcone.getGgps();
                String cconeid = dwcone.getDWBH() + "-(C:0)";
                String szwzone = "";
                String gyxsone = "";
                String ggccone = "";
                String zywtone = "";
                if (ggpones != null) {
                    cconeid = dwcone.getDWBH() + "-(X:" + ggpones.size() + ")";

                    Collections.sort(ggpones, new Comparator<GGP>() {
                        @Override
                        public int compare(GGP o1, GGP o2) {
                            //升序排序，降序反写
                            Integer o1id = Integer.valueOf(o1.getGGBH().substring(o1.getGGBH().indexOf("_")+1));
                            Integer o2id = Integer.valueOf(o2.getGGBH().substring(o2.getGGBH().indexOf("_")+1));
                            return o1id-o2id;
                        }
                    });
                    Map<String, Object> mapxzszwz = new HashMap<>();
                    Map<String, Object> mapxzgyxs = new HashMap<>();
                    Map<String, Object> mapxzggcc = new HashMap<>();
                    Map<String, Object> mapxzzywt = new HashMap<>();
                    for (GGP ggp : ggpones) {
                        String id = ggp.getGGBH().substring(ggp.getGGBH().indexOf("_")+1);
                        if (StringUtils.isNotBlank(ggp.getSZWZ())) {
                            if (ggp.getSZWZ().contains("其他") && StringUtils.isNotBlank(ggp.getQTWZ())){
                                CommonTools.getMapData(mapxzszwz, ggp.getQTWZ(), id);
                            }else {
                                CommonTools.getMapData(mapxzszwz, ggp.getSZWZ(), id);
                            }
                        }
                        if (StringUtils.isNotBlank(ggp.getGYXS())) {
                            CommonTools.getMapData(mapxzgyxs, ggp.getGYXS(), id);
                        }
                        if (StringUtils.isNotBlank(ggp.getGGCC())) {
                            String[] ggcc_str = ggp.getGGCC().split("×");
                            Double temp_1 = Double.valueOf(ggcc_str[0]);
                            if(ggcc_str[0].indexOf(".")>0){
                                temp_1 = Double.valueOf(ggcc_str[0].substring(0,ggcc_str[0].indexOf(".")+2));
                            }
                            Double temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf("=")));
                            if((ggcc_str[1].substring(0,ggcc_str[1].indexOf("="))).indexOf(".")>0){
                                temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf(".")+2));
                            }
                            DecimalFormat    df   = new DecimalFormat("######0.0");
                            String temp_3 = temp_1+"×"+temp_2+"="+ df.format(temp_1*temp_2)+"㎡";
                            CommonTools.getMapData(mapxzggcc, temp_3, id);
                        }
                        if(StringUtils.isNotBlank(ggp.getZYWT())) {
                            if (ggp.getZYWT().contains("其他") && StringUtils.isNotBlank(ggp.getQTWT())){
                                CommonTools.getMapData(mapxzzywt, ggp.getQTWT(), id);
                            }else {
                                CommonTools.getMapData(mapxzzywt, ggp.getZYWT(), id);
                            }

                        }
                    }
                    szwzone = CommonTools.mapSort(mapxzszwz);
                    gyxsone = CommonTools.mapSort(mapxzgyxs);
                    ggccone = CommonTools.mapSort(mapxzggcc);
                    zywtone = CommonTools.mapSort(mapxzzywt);
                }
                String jzqsone = dwcone.getJZQS();
                if (jzqsone != null) {
                    jzqsone = jzqsone.substring(0, jzqsone.indexOf("（可编辑"));
                    if (StringUtils.isNotBlank(dwcone.getQSMC())){
                        jzqsone+="("+dwcone.getQSMC()+")";
                    }
                }

                //现状图片
                String[] qwtsone = null;
                String[] xztsone = null;
                String qwtone = ccdwtpone.getQWT();
                String xztone = ccdwtpone.getXZT();
                if (StringUtils.isNotBlank(qwtone) && qwtone.contains(";")) {
                    qwtsone = qwtone.split(";");
                } else if (StringUtils.isNotBlank(qwtone)){
                    qwtsone = new String[]{qwtone};
                }
                if (StringUtils.isNotBlank(xztone) && xztone.contains(";")) {
                    xztsone = xztone.split(";");
                } else if (StringUtils.isNotBlank(xztone)){
                    xztsone = new String[]{xztone};
                }

                String[] GHRimagePath = null;
                String cctone = ccdwtpone.getCCT();
                if (StringUtils.isNotBlank(cctone) && cctone.contains(";")) {
                    GHRimagePath = cctone.split(";");
                } else if(StringUtils.isNotBlank(cctone)){
                    GHRimagePath = new String[]{cctone};
                }
                //结束
                XSLFSlide slide = slideShow.createSlide();
                XSLFTable tableCCone = slide.createTable();
                Object[][] datasCCone = {
                        {"现状点位编号："+cconeid, "", ""},
                        {"区位图", "现状基本信息", ""},
                        {"", "所在路段", (dwcone.getSZLD()!=null?dwcone.getSZLD():"——")},
                        {"", "建筑名称", (dwcone.getJZMC()!=null?dwcone.getJZMC():"——")},
                        {"", "建筑性质", (dwcone.getJZXZ()!=null?dwcone.getJZXZ():"——")},
                        {"", "建筑商业面积", (dwcone.getJZMJ()!=null?dwcone.getJZMJ():"——")},
                        {"", "建筑权属", (jzqsone!=null?jzqsone:"——")},
                        {"现状图", "专项规划分区", (dwcone.getZXGH()!=null?dwcone.getZXGH():"——")},
                        {"", "广告所在位置", (StringUtils.isNotBlank(szwzone)?szwzone:"——")},
                        {"", "广告工艺形式", (StringUtils.isNotBlank(gyxsone)?gyxsone:"——")},
                        {"", "广告规格尺寸", (StringUtils.isNotBlank(ggccone)?ggccone:"——")},
                        {"", "广告主要问题", (StringUtils.isNotBlank(zywtone)?zywtone:"——")}
                };
                for (int i = 0; i < datasCCone.length; i++) {
                    XSLFTableRow tableRow = tableCCone.addRow();
                    tableRow.setHeight(26D);
                    for (int j = 0; j < datasCCone[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(datasCCone[i][j]));
                        if (!(i == 1 && j == 0 || i == 7 && j == 0)) {
                            tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
                            p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        }

                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                        }
                        if (i > 0) {
                            tr.setFontSize(10D);
                        }
                        if (i == 0 || i == 1 || j == 0 || j == 1) {
                            tr.setBold(true);
                        }
                    }
                    if (i == 0) {
                        tableRow.mergeCells(0, 2);
                    }
                    if (i == 1) {
                        tableRow.mergeCells(1, 2);
                    }
                }
                tableCCone.setColumnWidth(0, 285);
                tableCCone.setColumnWidth(1, 80);
                tableCCone.setColumnWidth(2, 180);
                tableCCone.setRowHeight(10, 30D);
                tableCCone.setRowHeight(11, 80D);
                tableCCone.mergeCells(1, 6, 0, 0);
                tableCCone.mergeCells(7, 11, 0, 0);
                tableCCone.setAnchor(new Rectangle2D.Double(40, 30, 535, 370));

                String[] CConeimagePath = {
                        httpImagePath+qwtsone[0],
                        httpImagePath+xztsone[0],
                        httpImagePath+"/HWGGGH/hwggp/images/zbz.png"
//                    httpImagePath+"HWGGP/static/04.png",
//                    httpImagePath+"HWGGP/static/05.jpeg"
                };
                Double[][] CConepositionOffset = {
                        {85D, 65D, 228D, 143D},
                        {85D, 218D, 229D, 179D},
                        {45D, 80D, 38.08D, 44.24D},
                };
                for (int i = 0; i < CConeimagePath.length; i++) {
                    if (exist(CConeimagePath[i])) {
                        byte[] bytes = image2byte(CConeimagePath[i]);
                        XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                        XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                        picture.setAnchor(new Rectangle2D.Double(CConepositionOffset[i][0], CConepositionOffset[i][1], CConepositionOffset[i][2], CConepositionOffset[i][3]));
                    }
                }

                int jzqsOneHeight = jzqsone!=null?jzqsone.length():0;
                int szwzOneHeight = szwzone!=null?szwzone.length():0;
                int gyxsOneHeight = gyxsone!=null?gyxsone.length():0;
                int ggccOneHeight = ggccone!=null?ggccone.length():0;
                int zywtOneHeight = zywtone!=null?zywtone.length():0;
                double cconeTableHeight = 425D;
                double cconeImageHeight = 455D;
                while (jzqsOneHeight > 28) {
                    jzqsOneHeight -= 28;
                    cconeTableHeight += 20D;
                    cconeImageHeight += 20D;
                }
                while (szwzOneHeight > 28) {
                    szwzOneHeight -= 28;
                    cconeTableHeight += 20D;
                    cconeImageHeight += 20D;
                }
                while (gyxsOneHeight > 28) {
                    gyxsOneHeight -= 28;
                    cconeTableHeight += 20D;
                    cconeImageHeight += 20D;
                }
                while (ggccOneHeight > 56) {
                    ggccOneHeight -= 28;
                    cconeTableHeight += 20D;
                    cconeImageHeight += 20D;
                }
                while (zywtOneHeight > 145) {
                    zywtOneHeight -= 28;
                    cconeTableHeight += 20D;
                    cconeImageHeight += 20D;
                }

                XSLFTable tableGHR = slide.createTable();
                Object[][] GHR = {
                        {"规划图"},
                        {""},
                };
                for (int i = 0; i < GHR.length; i++) {
                    XSLFTableRow tableRow = tableGHR.addRow();
                    for (int j = 0; j < GHR[i].length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tr.setText(String.valueOf(GHR[i][j]));
                        tr.setFontFamily("微软雅黑");
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        tableStyle(tableCell);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(242, 242, 242));
                            tr.setFontSize(14D);
                            tr.setBold(true);
                        }
                    }
                }
                tableGHR.setRowHeight(0, 20);   //540
                tableGHR.setRowHeight(1, 350);   //540
                tableGHR.setColumnWidth(0, 544.88); //370
                tableGHR.setAnchor(new Rectangle2D.Double(40, cconeTableHeight, 200, 400));


//                Double[][] GHRpositionOffset = {
//                        {20D, cconeImageHeight, 320D, 220D},
//                };
                if (GHRimagePath!=null){
                    for (int i = 0; i < GHRimagePath.length; i++) {
                        if (exist(httpImagePath + GHRimagePath[i])) {
                            byte[] bytes = image2byte(httpImagePath + GHRimagePath[i]);
                            XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                            XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                            //                    picture.setAnchor(new Rectangle2D.Double(GHRpositionOffset[i][0], GHRpositionOffset[i][1], GHRpositionOffset[i][2], GHRpositionOffset[i][3]));
                            picture.setAnchor(new Rectangle2D.Double(75D, cconeImageHeight, 458D, 332D));
                        }
                    }
                }

                if (isTwo) {
                    //拆除two
                    if(dwctwo==null) {
                        continue;
                    }
                    DWTP ccdwtptwo = dwctwo.getDwtp();
                    if (ccdwtptwo == null) {
                        continue;
                    }
                    List<GGP> ggptwos = dwctwo.getGgps();
                    String cctwoid = dwctwo.getDWBH() + "-(C:0)";
                    String szwztwo = "";
                    String gyxstwo = "";
                    String ggcctwo = "";
                    String zywttwo = "";
                    if (ggptwos != null) {
                        cctwoid = dwctwo.getDWBH() + "-(X:" + ggptwos.size() + ")";

                        Collections.sort(ggptwos, new Comparator<GGP>() {
                            @Override
                            public int compare(GGP o1, GGP o2) {
                                //升序排序，降序反写
                                Integer o1id = Integer.valueOf(o1.getGGBH().substring(o1.getGGBH().indexOf("_")+1));
                                Integer o2id = Integer.valueOf(o2.getGGBH().substring(o2.getGGBH().indexOf("_")+1));
                                return o1id-o2id;
                            }
                        });
                        Map<String, Object> mapxzszwz = new HashMap<>();
                        Map<String, Object> mapxzgyxs = new HashMap<>();
                        Map<String, Object> mapxzggcc = new HashMap<>();
                        Map<String, Object> mapxzzywt = new HashMap<>();
                        for (GGP ggp : ggptwos) {
                            String id = ggp.getGGBH().substring(ggp.getGGBH().indexOf("_")+1);
                            if (StringUtils.isNotBlank(ggp.getSZWZ())) {
                                if (ggp.getSZWZ().contains("其他") && StringUtils.isNotBlank(ggp.getQTWZ())){
                                    CommonTools.getMapData(mapxzszwz, ggp.getQTWZ(), id);
                                }else {
                                    CommonTools.getMapData(mapxzszwz, ggp.getSZWZ(), id);
                                }
                            }
                            if (StringUtils.isNotBlank(ggp.getGYXS())) {
                                CommonTools.getMapData(mapxzgyxs, ggp.getGYXS(), id);
                            }
                            if (StringUtils.isNotBlank(ggp.getGGCC())) {
                                String[] ggcc_str = ggp.getGGCC().split("×");
                                Double temp_1 = Double.valueOf(ggcc_str[0]);
                                if(ggcc_str[0].indexOf(".")>0){
                                    temp_1 = Double.valueOf(ggcc_str[0].substring(0,ggcc_str[0].indexOf(".")+2));
                                }
                                Double temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf("=")));
                                if((ggcc_str[1].substring(0,ggcc_str[1].indexOf("="))).indexOf(".")>0){
                                    temp_2 = Double.valueOf(ggcc_str[1].substring(0,ggcc_str[1].indexOf(".")+2));
                                }
                                DecimalFormat    df   = new DecimalFormat("######0.0");
                                String temp_3 = temp_1+"×"+temp_2+"="+ df.format(temp_1*temp_2)+"㎡";
                                CommonTools.getMapData(mapxzggcc,temp_3, id);
                            }
                            if(StringUtils.isNotBlank(ggp.getZYWT())) {
                                if (ggp.getZYWT().contains("其他") && StringUtils.isNotBlank(ggp.getQTWT())){
                                    CommonTools.getMapData(mapxzzywt, ggp.getQTWT(), id);
                                }else {
                                    CommonTools.getMapData(mapxzzywt, ggp.getZYWT(), id);
                                }

                            }
                        }
                        szwztwo = CommonTools.mapSort(mapxzszwz);
                        gyxstwo = CommonTools.mapSort(mapxzgyxs);
                        ggcctwo = CommonTools.mapSort(mapxzggcc);
                        zywttwo = CommonTools.mapSort(mapxzzywt);
                    }
                    String jzqstwo = dwctwo.getJZQS();
                    if (jzqstwo != null) {
                        jzqstwo = jzqstwo.substring(0, jzqstwo.indexOf("（可编辑"));
                    }

                    //现状图片
                    String[] qwtstwo = null;
                    String[] xztstwo = null;
                    String qwttwo = ccdwtptwo.getQWT();
                    String xzttwo = ccdwtptwo.getXZT();
                    if (StringUtils.isNotBlank(qwttwo) && qwttwo.contains(";")) {
                        qwtstwo = qwttwo.split(";");
                    } else if (StringUtils.isNotBlank(qwttwo)){
                        qwtstwo = new String[]{qwttwo};
                    }
                    if (StringUtils.isNotBlank(xzttwo) && xzttwo.contains(";")) {
                        xztstwo = xzttwo.split(";");
                    } else if (StringUtils.isNotBlank(xzttwo)){
                        xztstwo = new String[]{xzttwo};
                    }
                    String[] GHYimagePath = null;
                    String ccttwo = ccdwtptwo.getCCT();
                    if (StringUtils.isNotBlank(ccttwo) && ccttwo.contains(";")) {
                        GHYimagePath = ccttwo.split(";");
                    } else if(StringUtils.isNotBlank(ccttwo)){
                        GHYimagePath = new String[]{ccttwo};
                    }
                    //结束
                    XSLFTable tableCCtwo = slide.createTable();
                    Object[][] datasCCtwo = {
                            {"现状点位编号："+cctwoid, "", ""},
                            {"区位图", "现状基本信息", ""},
                            {"", "所在路段", (dwctwo.getSZLD()!=null?dwctwo.getSZLD():"——")},
                            {"", "建筑名称",(dwctwo.getJZMC()!=null?dwctwo.getJZMC():"——")},
                            {"", "建筑性质", (dwctwo.getJZXZ()!=null?dwctwo.getJZXZ():"——")},
                            {"", "建筑商业面积", (dwctwo.getJZMJ()!=null?dwctwo.getJZMJ():"——")},
                            {"", "建筑权属", (jzqstwo!=null?jzqstwo:"——")},
                            {"现状图", "专项规划分区", (dwctwo.getZXGH()!=null?dwctwo.getZXGH():"——")},
                            {"", "广告所在位置", (StringUtils.isNotBlank(szwztwo)?szwztwo:"——")},
                            {"", "广告工艺形式", (StringUtils.isNotBlank(gyxstwo)?gyxstwo:"——")},
                            {"", "广告规格尺寸", (StringUtils.isNotBlank(ggcctwo)?ggcctwo:"——")},
                            {"", "广告主要问题", (StringUtils.isNotBlank(zywttwo)?zywttwo:"——")}
                    };
                    for (int i = 0; i < datasCCtwo.length; i++) {
                        XSLFTableRow tableRow = tableCCtwo.addRow();
                        tableRow.setHeight(26D);
                        for (int j = 0; j < datasCCtwo[i].length; j++) {
                            XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                            XSLFTextParagraph p = tableCell.addNewTextParagraph();
                            XSLFTextRun tr = p.addNewTextRun();
                            tr.setFontFamily("微软雅黑");
                            tr.setText(String.valueOf(datasCCtwo[i][j]));
                            if (!(i == 1 && j == 0 || i == 7 && j == 0)) {
                                tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
                                p.setTextAlign(TextParagraph.TextAlign.CENTER);
                            }

                            tableStyle(tableCell);
                            if (i == 0) {
                                tableCell.setFillColor(new Color(242, 242, 242));
                                tr.setFontSize(14D);
                            }
                            if (i > 0) {
                                tr.setFontSize(10D);
                            }
                            if (i == 0 || i == 1 || j == 0 || j == 1) {
                                tr.setBold(true);
                            }
                        }
                        if (i == 0) {
                            tableRow.mergeCells(0, 2);
                        }
                        if (i == 1) {
                            tableRow.mergeCells(1, 2);
                        }
                    }
                    tableCCtwo.setColumnWidth(0, 285);
                    tableCCtwo.setColumnWidth(1, 80);
                    tableCCtwo.setColumnWidth(2, 180);
                    tableCCtwo.setRowHeight(10,30D);
                    tableCCtwo.setRowHeight(11,80D);
                    tableCCtwo.mergeCells(1, 6, 0, 0);
                    tableCCtwo.mergeCells(7, 11, 0, 0);
                    tableCCtwo.setAnchor(new Rectangle2D.Double(595, 30, 535, 370));
                    String[] CCtwoimagePath = {
                            httpImagePath+qwtstwo[0],
                            httpImagePath+xztstwo[0],
                            httpImagePath+"/HWGGGH/hwggp/images/zbz.png"
//                    httpImagePath+"HWGGP/static/04.png",
//                    httpImagePath+"HWGGP/static/05.jpeg"
                    };
                    Double[][] CCtwopositionOffset = {
                            {640D, 65D, 228D, 143D},
                            {640D, 218D, 229D, 179D},
                            {600D, 80D, 38.08D, 44.24D},
                    };
                    for (int i = 0; i < CCtwoimagePath.length; i++) {
                        if (exist(CCtwoimagePath[i])) {
                            byte[] bytes = image2byte(CCtwoimagePath[i]);
                            XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                            XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                            picture.setAnchor(new Rectangle2D.Double(CCtwopositionOffset[i][0], CCtwopositionOffset[i][1], CCtwopositionOffset[i][2], CCtwopositionOffset[i][3]));
                        }
                    }

                    int jzqsTwoHeight = jzqstwo!=null?jzqstwo.length():0;
                    int szwzTwoHeight = szwztwo!=null?szwztwo.length():0;
                    int gyxsTwoHeight = gyxstwo!=null?gyxstwo.length():0;
                    int ggccTwoHeight = ggcctwo!=null?ggcctwo.length():0;
                    int zywtTwoHeight = zywttwo!=null?zywttwo.length():0;
                    double cctwoTableHeight = 425D;
                    double cctwoImageHeight = 455D;
                    while (jzqsTwoHeight > 28) {
                        jzqsTwoHeight -= 28;
                        cctwoTableHeight += 20D;
                        cctwoImageHeight += 20D;
                    }
                    while (szwzTwoHeight > 28) {
                        szwzTwoHeight -= 28;
                        cctwoTableHeight += 20D;
                        cctwoImageHeight += 20D;
                    }
                    while (gyxsTwoHeight > 28) {
                        gyxsTwoHeight -= 28;
                        cctwoTableHeight += 20D;
                        cctwoImageHeight += 20D;
                    }
                    while (ggccTwoHeight > 56) {
                        ggccTwoHeight -= 28;
                        cctwoTableHeight += 20D;
                        cctwoImageHeight += 20D;
                    }
                    while (zywtTwoHeight > 145) {
                        zywtTwoHeight -= 28;
                        cctwoTableHeight += 20D;
                        cctwoImageHeight += 20D;
                    }

                    XSLFTable tableGHY = slide.createTable();
                    Object[][] GHY = {
                            {"规划图"},
                            {""},
                    };
                    tableGHY.setAnchor(new Rectangle2D.Double(595, cctwoTableHeight, 200, 400));
                    for (int i = 0; i < GHY.length; i++) {
                        XSLFTableRow tableRow = tableGHY.addRow();
                        for (int j = 0; j < GHY[i].length; j++) {
                            XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                            XSLFTextParagraph p = tableCell.addNewTextParagraph();
                            XSLFTextRun tr = p.addNewTextRun();
                            tr.setFontFamily("微软雅黑");
                            tr.setText(String.valueOf(GHY[i][j]));
                            p.setTextAlign(TextParagraph.TextAlign.CENTER);
                            tableStyle(tableCell);
                            if (i == 0) {
                                tableCell.setFillColor(new Color(242, 242, 242));
                                tr.setFontSize(14D);
                                tr.setBold(true);
                            }
                        }
                    }
                    tableGHY.setRowHeight(0, 20);   //540
                    tableGHY.setRowHeight(1, 350);   //540
                    tableGHY.setColumnWidth(0, 544.88); //370

//                    Double[][] GHYpositionOffset = {
//                            {380D, cctwoImageHeight, 320D, 220D},
//                    };
                    if(GHYimagePath!=null) {
                        for (int i = 0; i < GHYimagePath.length; i++) {
                            if (exist(httpImagePath + GHYimagePath[i])) {
                                byte[] bytes = image2byte(httpImagePath + GHYimagePath[i]);
                                XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                                XSLFPictureShape picture = slide.createPicture(xslfPictureData);
//                        picture.setAnchor(new Rectangle2D.Double(GHYpositionOffset[i][0], GHYpositionOffset[i][1], GHYpositionOffset[i][2], GHYpositionOffset[i][3]));
                                picture.setAnchor(new Rectangle2D.Double(633D, cctwoImageHeight, 458D, 332D));
                            }
                        }
                    }
                }
                q=q+2;
                int num = q;
                System.out.println("已执行了:"+num);
                if (num>l) num=num-1;
                if (isBreak) {
                    break;
                }
            }while (true);
            System.out.println("执行完毕");
            String fileName = exportConditionVo.getXzq();
            String ssjd = exportConditionVo.getSsjd();
            if (StringUtils.isNotBlank(ssjd) && StringUtils.isNotEmpty(ssjd)){
                fileName += "_"+ssjd;
            }
            if (StringUtils.isBlank(fileName)) fileName = "";
            fileName += "(拆除一).pptx";
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            slideShow.write(byteArrayOutputStream);
            byte[] b = byteArrayOutputStream.toByteArray();
            MultipartFile file = new MockMultipartFile(fileName, fileName, MediaType.APPLICATION_OCTET_STREAM.toString(), b);
            FileResult fileResult = FileUtil.saveFileToPath(request, file, HwggConstants.SAVE_PATH + "ExportFile", HwggConstants.MAPPING_PATH + "ExportFile", file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")));
            if (fileResult.isFlag()){
                return Result.createSuccess(EnumErrorCode.SUCCESS_MESSAGE.toString("成功"),fileResult.getHttpUrl());
            }
        }catch (Exception e){
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
        return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString("失败"));
    }

    //图表的X轴位置
    double xChartOne; //第一个的图表
    double xChartTwo; //第二个的图表
    //图表的Y轴位置
    double yChartOne; //第一行的图表
    double yChartTwo; //第二行的图表
    //图表表格的X轴位置
    double xChartTableOne; //第一行的图表表格
    double xChartTableTwo; //第二个的图表表格
    //图表表格的Y轴位置
    double yChartTableOne;
    double yChartTableTwo;
    //标题表格
    double xTitleTable;
    double yTitleTable;

    private void setDefaultData(){
        //图表的X轴位置
        xChartOne = 2.5;
        xChartTwo = 15;
        //图表的Y轴位置
        yChartOne = 5;
        yChartTwo = 17;
        //图表表格的X轴位置
        xChartTableOne = 60;
        xChartTableTwo = 60;
        //图表表格的Y轴位置
        yChartTableOne = 80;
        yChartTableTwo = 420;
        //标题表格
        xTitleTable = 60;
        yTitleTable = 40;
    }

    /**
     * 总统计表
     * @param request
     * @param response
     * @param statisticsGraphVo
     * @return
     */
    @RequestMapping(value = "/Chart")
    public Result Chart(HttpServletRequest request, HttpServletResponse response,StatisticsGraphVo statisticsGraphVo,@RequestParam(value = "tcFiles",required = false) MultipartFile[] files){
        try {
            setDefaultData();//初始化

            boolean success = false;

            XMLSlideShow slideShow = new XMLSlideShow();
            slideShow.setPageSize(new java.awt.Dimension(1176, 831));

            StatisticsTableVo statisticsTableVo = new StatisticsTableVo(statisticsGraphVo.getXzq(),statisticsGraphVo.getSsjd());
            statisticsTableVo.setPageSize(0);
            statisticsTableVo.setLimit(0);

            if (createTcSlide(slideShow,files)) success=true;

            statisticsTableVo.setDwtype("X");
            if (createXZAndCCTable(slideShow,statisticsTableVo)) success=true; //现状统计表
            if (createXZChart(slideShow,statisticsGraphVo)) success=true;//现状图表
            statisticsTableVo.setDwtype("G");
            if (createGHTable(slideShow,statisticsTableVo)) success=true;//规划统计表
            if (createGHChart(slideShow,statisticsGraphVo)) success=true;//规划图表
            statisticsTableVo.setDwtype("C");
            if (createXZAndCCTable(slideShow,statisticsTableVo)) success=true;//现状统计表
            if (createCCChart(slideShow,statisticsGraphVo)) success=true;//拆除图表

            if (!success){
                return Result.createError(EnumErrorCode.ERROR_OBJECT_SEARCH.toString("无数据"));
            }

            String fileName = statisticsGraphVo.getXzq();
            String ssjd = statisticsGraphVo.getSsjd();
            if (StringUtils.isNotBlank(ssjd) && StringUtils.isNotEmpty(ssjd)){
                fileName += "_"+ssjd;
            }
            if (StringUtils.isBlank(fileName)) fileName = "";
            fileName += "(总统计表一).pptx";
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            slideShow.write(byteArrayOutputStream);
            byte[] b = byteArrayOutputStream.toByteArray();
            MultipartFile file = new MockMultipartFile(fileName, fileName, MediaType.APPLICATION_OCTET_STREAM.toString(), b);
            FileResult fileResult = FileUtil.saveFileToPath(request, file, HwggConstants.SAVE_PATH + "ExportFile", HwggConstants.MAPPING_PATH + "ExportFile", file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")));
            //FileResult fileResult = FileUtil.saveFileToPath(request, file, "", "", file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")));
            if (fileResult.isFlag()){
                return Result.createSuccess(EnumErrorCode.SUCCESS_MESSAGE.toString("成功"),fileResult.getHttpUrl());
            }
        }catch (Exception e){
            e.printStackTrace();
            return Result.createError(EnumErrorCode.ERROR_SYSTEM_UNKNOWN.toString());
        }
        return Result.createError(EnumErrorCode.ERROR_MESSAGE.toString("失败"));
    }

    /**
     * 图层幻灯片
     * @param slideShow
     * @param files
     */
    private boolean createTcSlide(XMLSlideShow slideShow,MultipartFile[] files){
        boolean success = false;
        try {
            int cs = 1;
            if (files!=null && files.length>0) {
                XSLFSlide slide = slideShow.createSlide();
                for (MultipartFile file : files) {
                    success = true;
                    byte[] bytes = file.getBytes();
                    //byte[] bytes = image2byte("http://120.78.141.5/HWGGP/TH10/GHT_01.png");
                    XSLFPictureData xslfPictureData = slideShow.addPicture(bytes, PictureData.PictureType.PNG);
                    XSLFPictureShape picture = slide.createPicture(xslfPictureData);
                    Rectangle2D r = new Rectangle(fromCM(2), fromCM(3), fromCM(38.50), fromCM(23.31));
                    //                picture.setAnchor(new Rectangle2D.Double(50D, 75D, 1075D, 600D));
                    if (cs == 1) {
                        picture.setAnchor(new Rectangle2D.Double(50D, 75D, 530D, 275D));
                    } else {
                        picture.setAnchor(new Rectangle2D.Double(50D, 400D, 530D, 275D));
                    }
                    cs++;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            success = false;
        }
        return success;
    }

    /**
     * 创建标题表格
     * @param slide
     * @param title
     */
    private void createTitleTable(XSLFSlide slide,String title) {
        createTitleTableXY(slide,title,null,null);
    }
    private void createTitleTableXY(XSLFSlide slide,String title,Double X,Double Y){
        XSLFTable titletable = slide.createTable(1, 1);
        XSLFTableCell cell = titletable.getCell(0, 0);
        XSLFTextParagraph p = cell.addNewTextParagraph();
        XSLFTextRun tr = p.addNewTextRun();
        tableStyle(cell); //表格公告样式
        p.setTextAlign(TextParagraph.TextAlign.CENTER);
        cell.setFillColor(new Color(58, 177, 188));//背景颜色
        tr.setBold(true); //字体加粗
        tr.setFontFamily("微软雅黑");
        tr.setText(title);
        tr.setFontSize(20D); //字体大小
        titletable.setRowHeight(0,25D);
        titletable.setColumnWidth(0,1050);
        titletable.setAnchor(new Rectangle2D.Double(X!=null?X:xTitleTable, Y!=null?Y:yTitleTable, 1050, 25));
    }

    /**
     * 现状和拆除统计表
     * @param slideShow
     * @param statisticsTableVo
     */
    private boolean createXZAndCCTable(XMLSlideShow slideShow,StatisticsTableVo statisticsTableVo){
        setDefaultData(); //重置默认值

        boolean success = false;

        Map<String,Object> rsmap = (Map<String, Object>) statisticsService.selectDWstatisticsTable(statisticsTableVo).getData();
        List<Map<String,Object>> list = (List<Map<String, Object>>) rsmap.get("rows");

        if (isList(list)) {

            success = true;
            Integer xuhao = 1;

            int ggpnum = 0 ;
            int page = 1;
            for (Map<String, Object> map : list) {
                Object count = map.get("COUNT") != null ? map.get("COUNT") : "0";
                ggpnum += Integer.valueOf(count.toString());
            }

            List<List<Map<String, Object>>> newList = CommonTools.createList(list, 25);//拆分list

            for (List<Map<String, Object>> mapList : newList) {
                Object[][] data = null;
                String dwname = "";
                if (statisticsTableVo.getDwtype() == "X") {
                    dwname = "现状";
                    data = new Object[][]{{"序号", "点位编号", "所在路段", "建筑名称","建筑权属","建筑属性",  "专项规划分区", "现状广告牌数量"}};
                } else {
                    dwname = "拆除";
                    data = new Object[][]{{"序号", "点位编号", "所在路段", "建筑名称","建筑权属","建筑属性",  "专项规划分区", "拆除广告牌数量"}};
                }
                List<Object[]> tabledata = new ArrayList(Arrays.asList(data));




                for (Map<String, Object> map : mapList) {

                    Object[] newdata = new Object[]{
                            xuhao,
                            map.get("DWBH") != null ? map.get("DWBH") : "——",
                            map.get("SZLD") != null ? map.get("SZLD") : "——",
                            map.get("JZMC") != null ? map.get("JZMC") : "——",
                            map.get("JZXZ") != null ? map.get("JZXZ") : "——",
                            map.get("JZQS") != null ? map.get("JZQS") : "——",
                            map.get("ZXGH") != null ? map.get("ZXGH") : "——",
                            map.get("COUNT") != null ?  map.get("COUNT") : "0"
                    };
                    tabledata.add(newdata);
                    xuhao++;
                }

                XSLFSlide slide = slideShow.createSlide();//创建幻灯片

                if (page==1)createTitleTable(slide,dwname+"：户外广告点位"+list.size()+"处，户外广告牌"+ggpnum+"块");//创建标题表格

                XSLFTable table = slide.createTable();
                for (int i = 0; i < tabledata.size(); i++) {
                    XSLFTableRow tableRow = table.addRow();
                    for (int j = 0; j < tabledata.get(i).length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tableStyle(tableCell); //表格公告样式
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(191, 191, 191));//背景颜色
                            tr.setFontColor(new Color(89, 89, 89));//字体颜色
                            tr.setBold(true); //字体加粗
                        } else {
                            tr.setFontColor(new Color(96, 96, 96));//字体颜色
                        }
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(tabledata.get(i)[j]));
                        tr.setFontSize(12D); //字体大小
                        //table.setColumnWidth(j, 350);
                    }
            /*if (i==1){
                tableRow.setHeight(290.5);
            }*/
                }
                table.setColumnWidth(0, 60D);
                table.setColumnWidth(1, 70D);
                table.setColumnWidth(2, 130D);
                table.setColumnWidth(3, 160D);
                table.setColumnWidth(4, 235D);
                table.setColumnWidth(5, 230D);
                table.setColumnWidth(6, 100D);
                table.setColumnWidth(7, 60D);
                table.setAnchor(new Rectangle2D.Double(60D, 100D, 963, 300.75));

                page++;
            }
        }

        return success;
    }

    /**
     * 规划统计表
     * @param slideShow
     * @param statisticsTableVo
     */
    private boolean createGHTable(XMLSlideShow slideShow,StatisticsTableVo statisticsTableVo){
        setDefaultData(); //重置默认值

        boolean success = false;

        Map<String,Object> rsmap = (Map<String, Object>) statisticsService.selectDWstatisticsTable(statisticsTableVo).getData();
        List<Map<String,Object>> list = (List<Map<String, Object>>) rsmap.get("rows");

        if (isList(list)) {

            success = true;
            Integer xuhao = 1;

            int ggpnum = 0 ;
            int page = 1;
            for (Map<String, Object> map : list) {
                Object count = map.get("COUNT") != null ? map.get("COUNT") : "0";
                ggpnum += Integer.valueOf(count.toString());
            }

            List<List<Map<String, Object>>> newList = CommonTools.createList(list, 25);//拆分list
            for (List<Map<String, Object>> mapList : newList) {
                Object[][] data = {{"序号", "点位编号", "所在路段", "建筑名称", "建筑权属", "规划政策分区", "规划广告牌数量", "保留广告牌数量", "提档广告牌数量", "新增广告牌数量", "拆除广告牌数量"}};
                List<Object[]> tabledata = new ArrayList(Arrays.asList(data));

                for (Map<String, Object> map : mapList) {
                    Object[] newdata = new Object[]{
                            xuhao,
                            map.get("DWBH") != null ? map.get("DWBH") : "——",
                            map.get("SZLD") != null ? map.get("SZLD") : "——",
                            map.get("JZMC") != null ? map.get("JZMC") : "——",
                            map.get("JZQS") != null ? map.get("JZQS") : "——",
                            map.get("ZCFQ") != null ? map.get("ZCFQ") : "——",
                            map.get("COUNT") != null ?  map.get("COUNT") : "0",
                            map.get("BLCOUNT") != null ? map.get("BLCOUNT") : "0",
                            map.get("TDCOUNT") != null ? map.get("TDCOUNT") : "0",
                            map.get("XZCOUNT") != null ? map.get("XZCOUNT") : "0",
                            map.get("CCCOUNT") != null ? map.get("CCCOUNT") : "0"};
                    tabledata.add(newdata);
                    xuhao++;
                }

                XSLFSlide slide = slideShow.createSlide();

                if(page==1)createTitleTable(slide,"规划：户外广告点位"+list.size()+"处，户外广告牌"+ggpnum+"块");//创建标题表格

                XSLFTable table = slide.createTable();
                for (int i = 0; i < tabledata.size(); i++) {
                    XSLFTableRow tableRow = table.addRow();
                    for (int j = 0; j < tabledata.get(i).length; j++) {
                        XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                        XSLFTextParagraph p = tableCell.addNewTextParagraph();
                        XSLFTextRun tr = p.addNewTextRun();
                        tableStyle(tableCell); //表格公告样式
                        p.setTextAlign(TextParagraph.TextAlign.CENTER);
                        if (i == 0) {
                            tableCell.setFillColor(new Color(191, 191, 191));//背景颜色
                            tr.setFontColor(new Color(89, 89, 89));//字体颜色
                            tr.setBold(true); //字体加粗
                        } else {
                            tr.setFontColor(new Color(96, 96, 96));//字体颜色
                        }
                        tr.setFontFamily("微软雅黑");
                        tr.setText(String.valueOf(tabledata.get(i)[j]));
                        tr.setFontSize(12D); //字体大小
                        //table.setColumnWidth(j, 350);
                    }
            /*if (i==1){
                tableRow.setHeight(290.5);
            }*/
                }
                table.setColumnWidth(0, 40D);
                table.setColumnWidth(1, 70D);
                table.setColumnWidth(2, 100D);
                table.setColumnWidth(3, 100D);
                table.setColumnWidth(4, 220D);
                table.setAnchor(new Rectangle2D.Double(30D, 100D, 963, 300.75));

                page++;
            }
        }
        return success;
    }



    /**
     * 现状图表幻灯片
     * @param slideShow
     * @param statisticsGraphVo
     */
    private boolean createXZChart(XMLSlideShow slideShow,StatisticsGraphVo statisticsGraphVo){
        setDefaultData(); //重置默认值

        boolean success = false;

        statisticsGraphVo.setXZTj("szwz");
        List<Map<String,Object>> szwz = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setXZTj("gyxs");
        List<Map<String,Object>> gyxs = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setXZTj("ggcc");
        String ggcc = (String) statisticsService.getCCSum(statisticsGraphVo).getData();
        statisticsGraphVo.setXZTj("zywt");
        List<Map<String,Object>> zywt = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setXZTj("jzqs");
        List<Map<String,Object>> jzqs = (List<Map<String, Object>>) statisticsService.GroupCountDW(statisticsGraphVo).getData();


        XSLFSlide slide = null;

        if (isList(szwz) || isList(gyxs) || "0".equals(ggcc)) {
            slide = slideShow.createSlide();//创建幻灯片
            success = true;

            Object[][] tableOne = {
                    {"广告所在位置", "广告工艺形式", "广告规格尺寸"},
                    {"", "", "广告面积共计" + ggcc + "平方米。"}
            };
            createChartTable(slide, xChartTableOne, yChartTableOne, tableOne);
            createPieChart(slideShow, slide, xChartOne, yChartOne, szwz);
            createPieChart(slideShow, slide, xChartTwo, yChartOne, gyxs);
        }else{
            xChartTableTwo = xChartTableOne; //修改表格二X轴偏移量
            yChartTableTwo = yChartTableOne; //修改表格二Y轴偏移量
            yChartTwo = yChartOne; //修改表格二中图表Y轴偏移量
        }

        if (isList(jzqs) || isList(zywt)) {

            if (slide==null){ //判断幻灯片如果为空则新建
                slide = slideShow.createSlide();//创建幻灯片
            }

            success = true;
            Object[][] tableTwo = {
                    {"点位权属统计", "广告主要问题"},
                    {"", ""}
            };
            createChartTable(slide, xChartTableTwo, yChartTableTwo, tableTwo);
            createPieChart(slideShow, slide, xChartOne, yChartTwo, jzqs);
            createPieChart(slideShow, slide, xChartTwo, yChartTwo, zywt);
        }

        return success;
    }

    /**
     * 规划图表幻灯片
     * @param slideShow
     * @param statisticsGraphVo
     */
    private boolean createGHChart(XMLSlideShow slideShow,StatisticsGraphVo statisticsGraphVo){
        setDefaultData(); //重置默认值

        boolean success = false;

        statisticsGraphVo.setGHTj("szwz");
        List<Map<String,Object>> szwz = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setGHTj("gyxs");
        List<Map<String,Object>> gyxs = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setGHTj("ggcc");
        String ggcc = (String) statisticsService.getCCSum(statisticsGraphVo).getData();
        statisticsGraphVo.setGHTj("zcfq");
        List<Map<String,Object>> zcfq = (List<Map<String, Object>>) statisticsService.GroupCountDW(statisticsGraphVo).getData();
        statisticsGraphVo.setGHTj("ghcs");
        List<Map<String,Object>> ghcs = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setFJGTj("ggpjg");
        String ggjg = (String) statisticsService.getJGSum(statisticsGraphVo).getData();

        XSLFSlide slide = null;

        if (isList(szwz) || isList(gyxs) || "0".equals(ggcc)) {
            slide = slideShow.createSlide();//创建幻灯片

            success = true;

            Object[][] tableOne = {
                    {"广告所在位置", "广告工艺形式", "广告规格尺寸"},
                    {"", "", "广告面积共计" + ggcc + "平方米。"}
            };
            createChartTable(slide, xChartTableOne, yChartTableOne, tableOne);
            createPieChart(slideShow, slide, xChartOne, yChartOne, szwz);
            createPieChart(slideShow, slide, xChartTwo, yChartOne, gyxs);
        }else{
            xChartTableTwo = xChartTableOne; //修改表格二X轴偏移量
            yChartTableTwo = yChartTableOne; //修改表格二Y轴偏移量
            yChartTwo = yChartOne; //修改表格二中图表Y轴偏移量
        }
        if (isList(zcfq) || isList(ghcs) || ("0".equals(ggjg) && StringUtils.isBlank(ggjg))) {
            if (StringUtils.isBlank(ggjg))ggjg="0";
            if (slide==null){ //判断幻灯片如果为空则新建
                slide = slideShow.createSlide();//创建幻灯片
            }

            success = true;

            Object[][] tableTwo = {
                    {"点位政策分区", "广告规划措施", "广告价值统计"},
                    {"", "", "广告价值共计"+ggjg+"万元。"}
            };
            createChartTable(slide, xChartTableTwo, yChartTableTwo, tableTwo);
            createPieChart(slideShow, slide, xChartOne, yChartTwo, zcfq);
            createBarChart(slideShow, slide, xChartTwo, yChartTwo, ghcs);
        }
        return success;
    }

    /**
     * 拆除图表幻灯片
     * @param slideShow
     * @param statisticsGraphVo
     */
    private boolean createCCChart(XMLSlideShow slideShow,StatisticsGraphVo statisticsGraphVo){
        setDefaultData(); //重置默认值

        boolean success = false;

        statisticsGraphVo.setCCTj("szwz");
        List<Map<String,Object>> szwz = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setCCTj("gyxs");
        List<Map<String,Object>> gyxs = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();
        statisticsGraphVo.setCCTj("ggcc");
        String ggcc = (String) statisticsService.getCCSum(statisticsGraphVo).getData();
        statisticsGraphVo.setCCTj("zywt");
        List<Map<String,Object>> zywt = (List<Map<String, Object>>) statisticsService.GroupCountGGP(statisticsGraphVo).getData();

        XSLFSlide slide = null;

        if (isList(szwz) || isList(gyxs) || "0".equals(ggcc)) {
            slide = slideShow.createSlide();//创建幻灯片

            success = true;
            Object[][] tableOne = {
                    {"广告所在位置", "广告工艺形式", "广告规格尺寸"},
                    {"", "", "广告面积共计" + ggcc + "平方米。"}
            };
            createChartTable(slide, xChartTableOne, yChartTableOne, tableOne);
            createPieChart(slideShow, slide, xChartOne, yChartOne, szwz);
            createPieChart(slideShow, slide, xChartTwo, yChartOne, gyxs);
        }else{
            xChartTableTwo = xChartTableOne; //修改表格二X轴偏移量
            yChartTableTwo = yChartTableOne; //修改表格二Y轴偏移量
            yChartTwo = yChartOne; //修改表格二中图表Y轴偏移量
        }
        if(isList(zywt)) {
            if (slide==null){ //判断幻灯片如果为空则新建
                slide = slideShow.createSlide();//创建幻灯片
            }

            success = true;
            Object[][] tableTwo = {
                    {"广告主要问题"},
                    {""}
            };
            createChartTable(slide, xChartTableTwo, yChartTableTwo, tableTwo);
            createPieChart(slideShow, slide, xChartOne, yChartTwo, zywt);
        }
        return success;
    }

    /**
     * 图表表格
     * @param slide
     * @param X
     * @param Y
     * @param tabledata
     */
    private void createChartTable(XSLFSlide slide,double X,double Y,Object[][] tabledata){
        XSLFTable table = slide.createTable();
        for (int i = 0 ; i < tabledata.length ; i++){
            XSLFTableRow tableRow = table.addRow();
            for (int j = 0 ; j < tabledata[i].length ; j++){
                XSLFTableCell tableCell = tableRow.addCell();//创建表格单元格
                XSLFTextParagraph p = tableCell.addNewTextParagraph();
                XSLFTextRun tr = p.addNewTextRun();
                tableStyle(tableCell); //表格公告样式
                if (i == 0) {
                    tableCell.setFillColor(new Color(58, 177, 188));//背景颜色
                    tr.setFontColor(new Color(255,255,255));//字体颜色
                }else{
                    tr.setFontColor(new Color(128,128,128));//字体颜色
                }
                tr.setFontFamily("微软雅黑");
                tr.setText(String.valueOf(tabledata[i][j]));
                tr.setFontSize(20D); //字体大小
                tr.setBold(true); //字体加粗
                table.setColumnWidth(j, 350);
            }
            if (i==1){
                tableRow.setHeight(290.5);
            }
        }
        table.setAnchor(new Rectangle2D.Double(X, Y, 963, 300.75));
    }

    /**
     * 饼图图表
     * @param slideShow
     * @param slide
     * @param X
     * @param Y
     * @param list
     */
    private void createPieChart(XMLSlideShow slideShow,XSLFSlide slide,double X,double Y,List<Map<String,Object>> list){
        List<String> xdata = new ArrayList<>();
        List<Integer> ydata = new ArrayList<>();

        if (isList(list)){
            for (Map<String, Object> map : list) {
                Object title = map.get("TITLE");
                Object count = map.get("COUNT");
                if (title!=null && count!=null){
                    xdata.add(title.toString());
                    ydata.add(Integer.valueOf(count.toString()));
                }
            }

            String[] xsData = ((String[]) xdata.toArray(new String[0]));
            Integer[] ysData = ((Integer[]) ydata.toArray(new Integer[0]));

            XSLFChart chart = slideShow.createChart(slide);//创建图表
            Rectangle2D r = new java.awt.Rectangle(fromCM(X), fromCM(Y),fromCM(11.10), fromCM(8.40));
            slide.addChart(chart,r);
            XDDFChartLegend orAddLegend = chart.getOrAddLegend();//图列项
            orAddLegend.setPosition(LegendPosition.BOTTOM);
            XDDFChartData data = chart.createData(ChartTypes.PIE, null, null);
            XDDFCategoryDataSource xs = XDDFDataSourcesFactory.fromArray(xsData);//X轴数据
            XDDFNumericalDataSource<Integer> ys = XDDFDataSourcesFactory.fromArray(ysData);//Y轴数据
            XDDFChartData.Series series = data.addSeries(xs, ys);//生成Series 系列/维度
            XDDFPieChartData pie = (XDDFPieChartData) data;
            chart.plot(pie);
        }
    }

    /**
     * 柱状图图表
     * @param slideShow
     * @param slide
     * @param X
     * @param Y
     * @param list
     */
    private void createBarChart(XMLSlideShow slideShow,XSLFSlide slide,double X,double Y,List<Map<String,Object>> list){
        List<String> xdata = new ArrayList<>();
        List<Integer> ydata = new ArrayList<>();

        if (isList(list)) {
            for (Map<String, Object> map : list) {
                Object title = map.get("TITLE");
                Object count = map.get("COUNT");
                if (title != null && count != null) {
                    xdata.add(title.toString());
                    ydata.add(Integer.valueOf(count.toString()));
                }
            }


            String[] xsData = ((String[]) xdata.toArray(new String[0]));
            Integer[] ysData = ((Integer[]) ydata.toArray(new Integer[0]));

            XSLFChart chart = slideShow.createChart(slide);//创建图表
            Rectangle2D r = new java.awt.Rectangle(fromCM(X), fromCM(Y), fromCM(11.10), fromCM(8.40));
            slide.addChart(chart, r);
            XDDFChartAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);//X轴和位置
            bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO);
            XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);//Y轴和位置
            leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
            leftAxis.setMajorTickMark(AxisTickMark.OUT);
            leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
            XDDFChartData data = chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);
            XDDFCategoryDataSource xs = XDDFDataSourcesFactory.fromArray(xsData);//X轴数据
            XDDFNumericalDataSource<Integer> ys = XDDFDataSourcesFactory.fromArray(ysData);//Y轴数据
            XDDFChartData.Series series = data.addSeries(xs, ys);//生成Series 系列/维度
            XDDFShapeProperties shapeProperties = series.getShapeProperties();
            XDDFBarChartData bar = (XDDFBarChartData) data;//由数据生成图表，Bar柱状图，Pie饼状图,Line折线图，Scatter散点图
            bar.setVaryColors(true);
            bar.setBarDirection(BarDirection.COL);//柱状如方向 BAR 竖向 COL横向
            chart.plot(bar);
        }
    }

    private boolean isList(List list){
        if (list!=null && list.size()>0){
            return true;
        }
        return false;
    }

    private int fromCM(double cm) {
        return (int) (Math.rint(cm * Units.EMU_PER_CENTIMETER));
    }


/*    public void getMapData(Map<String,Object> map,String condition,String number){
        if (map.containsKey(condition)){
            String mapval = (String) map.get(condition);
            String orid = mapval;
            String one = "0";
            int i1 = mapval.lastIndexOf("/");
            int i2 = mapval.lastIndexOf("-");
            Integer intid = Integer.valueOf(number);
            if (i2<i1){
                one = mapval.substring(i1+1);
                orid = mapval;
            }else if (i1<i2){
                one = mapval.substring(i2+1);
                orid = mapval.substring(0,i2);
            }else{
                one = mapval;
            }
            Integer intone = Integer.valueOf(one);
            if (intone<intid && intone+1==intid){
                map.put(condition,orid+"-"+number);
            }else if (intone<intid && intone+1!=intid){
                map.put(condition,orid+"/"+number);
            }
        }else {
            map.put(condition,number);
        }
    }*/

    /**
     * 表格公共样式
     * @param tableCell
     */
    public static void tableStyle(XSLFTableCell tableCell){
//        tableCell.setFillColor(Color.getColor("0xdd7e6b"));
//        tableCell.setVerticalAlignment(VerticalAlignment.MIDDLE);
        tableCell.setBorderCompound(TableCell.BorderEdge.bottom, StrokeStyle.LineCompound.DOUBLE);
        tableCell.setBorderCompound(TableCell.BorderEdge.left, StrokeStyle.LineCompound.DOUBLE);
        tableCell.setBorderCompound(TableCell.BorderEdge.top, StrokeStyle.LineCompound.DOUBLE);
        tableCell.setBorderCompound(TableCell.BorderEdge.right, StrokeStyle.LineCompound.DOUBLE);
        tableCell.setBorderColor(TableCell.BorderEdge.bottom,Color.BLACK);
        tableCell.setBorderColor(TableCell.BorderEdge.left,Color.BLACK);
        tableCell.setBorderColor(TableCell.BorderEdge.top,Color.BLACK);
        tableCell.setBorderColor(TableCell.BorderEdge.right,Color.BLACK);
    }


    /**
     * 判断url是否是404
     * @param url
     * @return
     */
    private static boolean exist(String url) {
        try {
            URL u = new URL(url);
            HttpURLConnection huc = (HttpURLConnection) u.openConnection();
            huc.setRequestMethod ("HEAD");
            huc.setConnectTimeout(5000); //视情况设置超时时间
            huc.connect();
            return huc.getResponseCode() == HttpURLConnection.HTTP_OK;
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 图片转为byte数组
     *
     * @param path
     * @return
     */
    public static byte[] image2byte(String path) throws IOException {
        byte[] data = null;
        URL url = null;
        InputStream input = null;
        try{
            url = new URL(path);
            HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
            httpUrl.connect();
            httpUrl.getInputStream();
            input = httpUrl.getInputStream();
        }catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int numBytesRead = 0;
        while ((numBytesRead = input.read(buf)) != -1) {
            output.write(buf, 0, numBytesRead);
        }
        data = output.toByteArray();
        output.close();
        input.close();
        return data;
    }
}
